package gameDump;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;

/**
 *
 * @author Robin
 */
public class Maze {

    //private Graphics2D g2d;
    private static int nrofblocks = 15;
    private static int blocksize = 24;
    private int scrsize;
    private Image grass;
    private Color mazecolor, dotcolor;
    //private short[] screendata;
    private int[][] screendata;
    final short leveldata[] = {19, 26, 26, 26, 18, 18, 18, 18, 18, 18, 18, 18, 18, 18, 22,
        21, 0, 0, 0, 17, 16, 16, 16, 16, 16, 16, 16, 16, 16, 20,
        21, 0, 0, 0, 17, 16, 16, 16, 16, 16, 16, 16, 16, 16, 20,
        21, 0, 0, 0, 17, 16, 16, 24, 16, 16, 16, 16, 16, 16, 20,
        17, 18, 18, 18, 16, 16, 20, 0, 17, 16, 16, 16, 16, 16, 20,
        17, 16, 16, 16, 16, 16, 20, 0, 17, 16, 16, 16, 16, 24, 20,
        25, 16, 16, 16, 24, 24, 28, 0, 25, 24, 24, 16, 20, 0, 21,
        1, 17, 16, 20, 0, 0, 0, 0, 0, 0, 0, 17, 20, 0, 21,
        1, 17, 16, 16, 18, 18, 22, 0, 19, 18, 18, 16, 20, 0, 21,
        1, 17, 16, 16, 16, 16, 20, 0, 17, 16, 16, 16, 20, 0, 21,
        1, 17, 16, 16, 16, 16, 20, 0, 17, 16, 16, 16, 20, 0, 21,
        1, 17, 16, 16, 16, 16, 16, 18, 16, 16, 16, 16, 20, 0, 21,
        1, 17, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 20, 0, 21,
        1, 25, 24, 24, 24, 24, 24, 24, 24, 24, 16, 16, 16, 18, 20,
        9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 25, 24, 24, 24, 28};
    final static int[][] leveldata2 = {
        {1, 0, 1, 1}, {1, 0, 1, 0}, {1, 0, 1, 0}, {1, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 0, 0}, {0, 1, 0, 0}, {1, 0, 0, 1}, {1, 0, 0, 0}, {1, 0, 0, 0}, {1, 1, 0, 0}, {0, 0, 1, 1}, {0, 1, 1, 0},
        {1, 0, 0, 0}, {1, 0, 1, 0}, {1, 1, 1, 0}, {0, 0, 0, 1}, {0, 1, 0, 0}, {0, 0, 1, 1}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 1}, {0, 0, 0, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {1, 0, 0, 0}, {1, 1, 0, 0},
        {0, 1, 0, 0}, {1, 0, 0, 1}, {1, 0, 0, 0}, {0, 0, 0, 0}, {0, 0, 0, 0}, {1, 0, 0, 0}, {1, 0, 0, 0}, {1, 0, 0, 0}, {1, 0, 0, 0}, {0, 0, 0, 0}, {0, 1, 0, 0}, {1, 0, 0, 1}, {1, 1, 0, 0}, {0, 0, 0, 1}, {0, 1, 0, 0},
        {0, 1, 0, 0}, {0, 0, 1, 1}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 1}, {0, 1, 0, 0}, {0, 0, 0, 1}, {0, 1, 0, 0},
        {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
        {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
        {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
        {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
        {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
        {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
        {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
        {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
        {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
        {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {},
        {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {}
    };

    public Maze() {
        mazecolor = new Color(5, 100, 5);
        dotcolor = new Color(192, 192, 0);
        scrsize = nrofblocks * blocksize;

        grass = new ImageIcon(this.getClass().getResource("/images/pacman/grass.png")).getImage().getScaledInstance(25, 25, Image.SCALE_FAST);

        //screendata=new short[nrofblocks*nrofblocks];
        screendata = new int[nrofblocks * nrofblocks][4];
        levelInit();
    }

    public static int getNrofblocks() {
        return nrofblocks;
    }

    public static int getBlockSize() {
        return blocksize;
    }

    public void levelInit() {
        /*for(int i=0;i<nrofblocks*nrofblocks;i++){
         screendata[i]=leveldata[i];
         }*/
        for (int i = 0; i < nrofblocks * nrofblocks; i++) {
            for (int j = 0; j < leveldata2[i].length; j++) {
                screendata[i][j] = leveldata2[i][j];
            }

        }
    }

    public void DrawMaze(Graphics2D g2d) {
        short i = 0;
        int x, y;

        for (y = 0; y < scrsize; y += blocksize) {
            for (x = 0; x < scrsize; x += blocksize) {

                g2d.setColor(mazecolor);
                g2d.setStroke(new BasicStroke(2));


                if (screendata[i][0] == 1) {
                    g2d.drawLine(x, y, x + blocksize - 1, y);
                }
                if (screendata[i][1] == 1) {
                    g2d.drawLine(x + blocksize - 1, y, x + blocksize - 1, y + blocksize - 1);
                }
                if (screendata[i][2] == 1) {

                    g2d.drawLine(x, y + blocksize - 1, x + blocksize - 1, y + blocksize - 1);
                }
                if (screendata[i][3] == 1) {

                    g2d.drawLine(x, y, x, y + blocksize - 1);
                }

                /*
                 if(screendata[i]==1){
                 g2d.drawLine(x, y, x, y+blocksize-1);
                 }
                 if(screendata[i]==2){
                 g2d.drawLine(x+blocksize-1, y, x+blocksize-1, y+blocksize-1);
                 }
                 if(screendata[i]==3){
                 g2d.drawLine(x, y, x+blocksize-1, y);
                 }
                 if(screendata[i]==4){
                 g2d.drawLine(x, y+blocksize-1, x+blocksize-1, y+blocksize-1);
                 }
                 if(screendata[i]==5){
                 //draw dot
                 }
                 if(screendata[i]==0){
                 g2d.drawImage(grass, x, y, null);
                 }
                 * */

                /*
                 if((screendata[i]&1)!=0){//drawleft
                 g2d.drawLine(x, y, x, y+blocksize+1);
                 }
                 if ((screendata[i] & 2) != 0) // draws top
                 {
                 g2d.drawLine(x, y, x + blocksize - 1, y);
                 }
                 if ((screendata[i] & 4) != 0) // draws right
                 {
                 g2d.drawLine(x + blocksize - 1, y, x + blocksize - 1,
                 y + blocksize - 1);
                 }
                 if ((screendata[i] & 8) != 0) // draws bottom
                 {
                 g2d.drawLine(x, y + blocksize - 1, x + blocksize - 1,
                 y + blocksize - 1);
                 }
                 if ((screendata[i] & 16) != 0) // draws point
                 {
                 g2d.setColor(dotcolor);
                 g2d.fillRect(x + 11, y + 11, 2, 2);
                 }*/
                i++;

            }//inner for
        }//outer for


    }
}
